/**
 * 
 */
package vy.org.app.page.lookup.cities;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.lookup.VyLookupCitiesDAO;
import org.vy.dal.dao.lookup.VyLookupCitiesDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;

/**
 * @author Ravi Shankar
 * 
 */
public class MntnCitiesAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		MntnCitiesForm form = (MntnCitiesForm) actionForm;
		VyLookupCitiesDO dto = new VyLookupCitiesDO();

		if (form != null && form.getMode() != null) {
			if (ModeEnum.ADD.getName().equals(form.getMode())) {
				System.out.println("ADD");
				dto = MntnCitiesAssembler.getAssembler().getCities(form);

				try {
					VyLookupCitiesDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.DELETE.getName().equals(form.getMode())) {
				System.out.println("DELETE");
				dto = MntnCitiesAssembler.getAssembler().getCities(form);
				try {

					VyLookupCitiesDAO.delete(dto.getCityCode());
				} catch (Exception e) {
					e.printStackTrace();
				}

			} else if (ModeEnum.SEARCH.getName().equals(form.getMode())) {
				System.out.println("SEARCH");
				dto = MntnCitiesAssembler.getAssembler().getCities(form);
				try {

					request.setAttribute(AppConstants.RESULT, VyLookupCitiesDAO
							.showCitiesList(dto));
				} catch (Exception e) {
					e.printStackTrace();
				}

			}

		}
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {

		return ModuleEnum.MAINTAIN_CITIES;
	}

}
